﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace snat.util {
    /// <summary>
    /// This class defines a dataseries
    /// </summary>
    public class DataSeries : INotifyPropertyChanged {

        private List<DataPoint> series;
        public List<DataPoint> Series {
            get { return series; }
            set {
                series = value;
                if (PropertyChanged != null) {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Series"));
                }
            }
        }

        private string seriesName;
        public string SeriesName {
            get { return seriesName; }
            set {
                seriesName = value;
                if (PropertyChanged != null) {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("SeriesName"));
                }
            }
        }

        // Construct with with a name and a series
        public DataSeries(string name, List<DataPoint> series) {
            SeriesName = name;
            Series = series;
        }

        // Construct with a data series name
        public DataSeries(string name) {
            SeriesName = name;
            Series = new List<DataPoint>();
        }

        // Find if all elements within the series are of the same type (dependent and independent respectively)
        public bool IsValid() {
            if (Series.Count > 0) {
                Type x = Series.First().IndependentValue.GetType();
                Type y = Series.First().DependentValue.GetType();
                foreach (DataPoint pt in Series) {
                    if (!pt.IndependentValue.GetType().Equals(x)) return false;
                    if (!pt.DependentValue.GetType().Equals(y)) return false;
                }
            }
            return true;
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
